use ::libc;
extern "C" {
    pub type event_base;
    pub type evbuffer;
    pub type bufferevent_ops;
    pub type cmds;
    pub type hyperlinks;
    pub type screen_write_cline;
    pub type screen_sel;
    pub type screen_titles;
    pub type format_tree;
    pub type options;
    pub type environ;
    pub type tmuxpeer;
    pub type tty_key;
    pub type tty_code;
    pub type format_job_tree;
    pub type control_state;
    pub type cmdq_list;
    pub type input_ctx;
    pub type cmdq_item;
    pub type cmd;
    fn __ctype_b_loc() -> *mut *const u16;
    fn free(_: *mut libc::c_void);
    fn strchr(_: *const i8, _: i32) -> *mut i8;
    fn strcspn(_: *const i8, _: *const i8) -> u64;
    fn strlen(_: *const i8) -> u64;
    fn strtonum(
        _: *const i8,
        _: i64,
        _: i64,
        _: *mut *const i8,
    ) -> i64;
    fn strlcat(_: *mut i8, _: *const i8, _: size_t) -> size_t;
    fn xcalloc(_: size_t, _: size_t) -> *mut libc::c_void;
    fn xrealloc(_: *mut libc::c_void, _: size_t) -> *mut libc::c_void;
    fn xrecallocarray(_: *mut libc::c_void, _: size_t, _: size_t, _: size_t) -> *mut libc::c_void;
    fn xstrdup(_: *const i8) -> *mut i8;
    fn xasprintf(_: *mut *mut i8, _: *const i8, _: ...) -> i32;
    fn xvasprintf(
        _: *mut *mut i8,
        _: *const i8,
        _: ::core::ffi::VaList,
    ) -> i32;
    fn format_single_from_target(_: *mut cmdq_item, _: *const i8) -> *mut i8;
    fn cmd_list_free(_: *mut cmd_list);
    fn cmd_list_print(_: *mut cmd_list, _: i32) -> *mut i8;
    fn cmd_list_copy(_: *mut cmd_list, _: i32, _: *mut *mut i8) -> *mut cmd_list;
    fn cmd_template_replace(
        _: *const i8,
        _: *const i8,
        _: i32,
    ) -> *mut i8;
    fn cmd_log_argv(_: i32, _: *mut *mut i8, _: *const i8, _: ...);
    fn cmd_append_argv(_: *mut i32, _: *mut *mut *mut i8, _: *const i8);
    fn server_client_unref(_: *mut client);
    fn cmdq_error(_: *mut cmdq_item, _: *const i8, _: ...);
    fn cmd_parse_from_string(
        _: *const i8,
        _: *mut cmd_parse_input,
    ) -> *mut cmd_parse_result;
    fn cmdq_get_target(_: *mut cmdq_item) -> *mut cmd_find_state;
    fn cmd_find_copy_state(_: *mut cmd_find_state, _: *mut cmd_find_state);
    fn cmdq_get_target_client(_: *mut cmdq_item) -> *mut client;
    fn cmd_get_source(_: *mut cmd, _: *mut *const i8, _: *mut u_int);
    fn cmd_get_args(_: *mut cmd) -> *mut args;
    fn cmd_get_entry(_: *mut cmd) -> *const cmd_entry;
    fn cmd_list_first(_: *mut cmd_list) -> *mut cmd;
    fn utf8_stravis(
        _: *mut *mut i8,
        _: *const i8,
        _: i32,
    ) -> i32;
    fn fatalx(_: *const i8, _: ...) -> !;
    fn log_debug(_: *const i8, _: ...);
}
pub type __builtin_va_list = [__va_list_tag; 1];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct __va_list_tag {
    pub gp_offset: u32,
    pub fp_offset: u32,
    pub overflow_arg_area: *mut libc::c_void,
    pub reg_save_area: *mut libc::c_void,
}
pub type __u_char = u8;
pub type __u_short = u16;
pub type __u_int = u32;
pub type __uint8_t = u8;
pub type __uint64_t = u64;
pub type __pid_t = i32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_short = __u_short;
pub type u_int = __u_int;
pub type pid_t = __pid_t;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type C2RustUnnamed = u32;
pub const _ISalnum: C2RustUnnamed = 8;
pub const _ISpunct: C2RustUnnamed = 4;
pub const _IScntrl: C2RustUnnamed = 2;
pub const _ISblank: C2RustUnnamed = 1;
pub const _ISgraph: C2RustUnnamed = 32768;
pub const _ISprint: C2RustUnnamed = 16384;
pub const _ISspace: C2RustUnnamed = 8192;
pub const _ISxdigit: C2RustUnnamed = 4096;
pub const _ISdigit: C2RustUnnamed = 2048;
pub const _ISalpha: C2RustUnnamed = 1024;
pub const _ISlower: C2RustUnnamed = 512;
pub const _ISupper: C2RustUnnamed = 256;
pub type va_list = __builtin_va_list;
pub type cc_t = u8;
pub type speed_t = u32;
pub type tcflag_t = u32;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_line: cc_t,
    pub c_cc: [cc_t; 32],
    pub c_ispeed: speed_t,
    pub c_ospeed: speed_t,
}
pub type uint8_t = __uint8_t;
pub type uint64_t = __uint64_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event {
    pub ev_evcallback: event_callback,
    pub ev_timeout_pos: C2RustUnnamed_5,
    pub ev_fd: i32,
    pub ev_base: *mut event_base,
    pub ev_: C2RustUnnamed_0,
    pub ev_events: i16,
    pub ev_res: i16,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_0 {
    pub ev_io: C2RustUnnamed_3,
    pub ev_signal: C2RustUnnamed_1,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub ev_signal_next: C2RustUnnamed_2,
    pub ev_ncalls: i16,
    pub ev_pncalls: *mut i16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub ev_io_next: C2RustUnnamed_4,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_4 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_5 {
    pub ev_next_with_common_timeout: C2RustUnnamed_6,
    pub min_heap_idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_6 {
    pub tqe_next: *mut event,
    pub tqe_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_callback {
    pub evcb_active_next: C2RustUnnamed_8,
    pub evcb_flags: i16,
    pub evcb_pri: uint8_t,
    pub evcb_closure: uint8_t,
    pub evcb_cb_union: C2RustUnnamed_7,
    pub evcb_arg: *mut libc::c_void,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_7 {
    pub evcb_callback:
        Option<unsafe extern "C" fn(i32, i16, *mut libc::c_void) -> ()>,
    pub evcb_selfcb: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
    pub evcb_evfinalize: Option<unsafe extern "C" fn(*mut event, *mut libc::c_void) -> ()>,
    pub evcb_cbfinalize: Option<unsafe extern "C" fn(*mut event_callback, *mut libc::c_void) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub tqe_next: *mut event_callback,
    pub tqe_prev: *mut *mut event_callback,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct bufferevent {
    pub ev_base: *mut event_base,
    pub be_ops: *const bufferevent_ops,
    pub ev_read: event,
    pub ev_write: event,
    pub input: *mut evbuffer,
    pub output: *mut evbuffer,
    pub wm_read: event_watermark,
    pub wm_write: event_watermark,
    pub readcb: bufferevent_data_cb,
    pub writecb: bufferevent_data_cb,
    pub errorcb: bufferevent_event_cb,
    pub cbarg: *mut libc::c_void,
    pub timeout_read: timeval,
    pub timeout_write: timeval,
    pub enabled: i16,
}
pub type bufferevent_event_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, i16, *mut libc::c_void) -> ()>;
pub type bufferevent_data_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, *mut libc::c_void) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_watermark {
    pub low: size_t,
    pub high: size_t,
}
pub type bitstr_t = u8;
pub type msgtype = u32;
pub const MSG_READ_CANCEL: msgtype = 307;
pub const MSG_WRITE_CLOSE: msgtype = 306;
pub const MSG_WRITE_READY: msgtype = 305;
pub const MSG_WRITE: msgtype = 304;
pub const MSG_WRITE_OPEN: msgtype = 303;
pub const MSG_READ_DONE: msgtype = 302;
pub const MSG_READ: msgtype = 301;
pub const MSG_READ_OPEN: msgtype = 300;
pub const MSG_FLAGS: msgtype = 218;
pub const MSG_EXEC: msgtype = 217;
pub const MSG_WAKEUP: msgtype = 216;
pub const MSG_UNLOCK: msgtype = 215;
pub const MSG_SUSPEND: msgtype = 214;
pub const MSG_OLDSTDOUT: msgtype = 213;
pub const MSG_OLDSTDIN: msgtype = 212;
pub const MSG_OLDSTDERR: msgtype = 211;
pub const MSG_SHUTDOWN: msgtype = 210;
pub const MSG_SHELL: msgtype = 209;
pub const MSG_RESIZE: msgtype = 208;
pub const MSG_READY: msgtype = 207;
pub const MSG_LOCK: msgtype = 206;
pub const MSG_EXITING: msgtype = 205;
pub const MSG_EXITED: msgtype = 204;
pub const MSG_EXIT: msgtype = 203;
pub const MSG_DETACHKILL: msgtype = 202;
pub const MSG_DETACH: msgtype = 201;
pub const MSG_COMMAND: msgtype = 200;
pub const MSG_IDENTIFY_TERMINFO: msgtype = 112;
pub const MSG_IDENTIFY_LONGFLAGS: msgtype = 111;
pub const MSG_IDENTIFY_STDOUT: msgtype = 110;
pub const MSG_IDENTIFY_FEATURES: msgtype = 109;
pub const MSG_IDENTIFY_CWD: msgtype = 108;
pub const MSG_IDENTIFY_CLIENTPID: msgtype = 107;
pub const MSG_IDENTIFY_DONE: msgtype = 106;
pub const MSG_IDENTIFY_ENVIRON: msgtype = 105;
pub const MSG_IDENTIFY_STDIN: msgtype = 104;
pub const MSG_IDENTIFY_OLDCWD: msgtype = 103;
pub const MSG_IDENTIFY_TTYNAME: msgtype = 102;
pub const MSG_IDENTIFY_TERM: msgtype = 101;
pub const MSG_IDENTIFY_FLAGS: msgtype = 100;
pub const MSG_VERSION: msgtype = 12;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args {
    pub tree: args_tree,
    pub count: u_int,
    pub values: *mut args_value,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_value {
    pub type_0: args_type,
    pub c2rust_unnamed: C2RustUnnamed_10,
    pub cached: *mut i8,
    pub entry: C2RustUnnamed_9,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_9 {
    pub tqe_next: *mut args_value,
    pub tqe_prev: *mut *mut args_value,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_10 {
    pub string: *mut i8,
    pub cmdlist: *mut cmd_list,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
pub type args_type = u32;
pub const ARGS_COMMANDS: args_type = 2;
pub const ARGS_STRING: args_type = 1;
pub const ARGS_NONE: args_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_tree {
    pub rbh_root: *mut args_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_entry {
    pub flag: u_char,
    pub values: args_values,
    pub count: u_int,
    pub flags: i32,
    pub entry: C2RustUnnamed_11,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_11 {
    pub rbe_left: *mut args_entry,
    pub rbe_right: *mut args_entry,
    pub rbe_parent: *mut args_entry,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_values {
    pub tqh_first: *mut args_value,
    pub tqh_last: *mut *mut args_value,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_command_state {
    pub cmdlist: *mut cmd_list,
    pub cmd: *mut i8,
    pub pi: cmd_parse_input,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_input {
    pub flags: i32,
    pub file: *const i8,
    pub line: u_int,
    pub item: *mut cmdq_item,
    pub c: *mut client,
    pub fs: cmd_find_state,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_find_state {
    pub flags: i32,
    pub current: *mut cmd_find_state,
    pub s: *mut session,
    pub wl: *mut winlink,
    pub w: *mut window,
    pub wp: *mut window_pane,
    pub idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane {
    pub id: u_int,
    pub active_point: u_int,
    pub window: *mut window,
    pub options: *mut options,
    pub layout_cell: *mut layout_cell,
    pub saved_layout_cell: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub flags: i32,
    pub sb_slider_y: u_int,
    pub sb_slider_h: u_int,
    pub argc: i32,
    pub argv: *mut *mut i8,
    pub shell: *mut i8,
    pub cwd: *mut i8,
    pub pid: pid_t,
    pub tty: [i8; 32],
    pub status: i32,
    pub dead_time: timeval,
    pub fd: i32,
    pub event: *mut bufferevent,
    pub offset: window_pane_offset,
    pub base_offset: size_t,
    pub resize_queue: window_pane_resizes,
    pub resize_timer: event,
    pub ictx: *mut input_ctx,
    pub cached_gc: grid_cell,
    pub cached_active_gc: grid_cell,
    pub palette: colour_palette,
    pub pipe_fd: i32,
    pub pipe_event: *mut bufferevent,
    pub pipe_offset: window_pane_offset,
    pub screen: *mut screen,
    pub base: screen,
    pub status_screen: screen,
    pub status_size: size_t,
    pub modes: C2RustUnnamed_15,
    pub searchstr: *mut i8,
    pub searchregex: i32,
    pub border_gc_set: i32,
    pub border_gc: grid_cell,
    pub control_bg: i32,
    pub control_fg: i32,
    pub scrollbar_style: style,
    pub entry: C2RustUnnamed_14,
    pub sentry: C2RustUnnamed_13,
    pub tree_entry: C2RustUnnamed_12,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_12 {
    pub rbe_left: *mut window_pane,
    pub rbe_right: *mut window_pane,
    pub rbe_parent: *mut window_pane,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_13 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style {
    pub gc: grid_cell,
    pub ignore: i32,
    pub fill: i32,
    pub align: style_align,
    pub list: style_list,
    pub range_type: style_range_type,
    pub range_argument: u_int,
    pub range_string: [i8; 16],
    pub width: i32,
    pub pad: i32,
    pub default_type: style_default_type,
}
pub type style_default_type = u32;
pub const STYLE_DEFAULT_POP: style_default_type = 2;
pub const STYLE_DEFAULT_PUSH: style_default_type = 1;
pub const STYLE_DEFAULT_BASE: style_default_type = 0;
pub type style_range_type = u32;
pub const STYLE_RANGE_USER: style_range_type = 6;
pub const STYLE_RANGE_SESSION: style_range_type = 5;
pub const STYLE_RANGE_WINDOW: style_range_type = 4;
pub const STYLE_RANGE_PANE: style_range_type = 3;
pub const STYLE_RANGE_RIGHT: style_range_type = 2;
pub const STYLE_RANGE_LEFT: style_range_type = 1;
pub const STYLE_RANGE_NONE: style_range_type = 0;
pub type style_list = u32;
pub const STYLE_LIST_RIGHT_MARKER: style_list = 4;
pub const STYLE_LIST_LEFT_MARKER: style_list = 3;
pub const STYLE_LIST_FOCUS: style_list = 2;
pub const STYLE_LIST_ON: style_list = 1;
pub const STYLE_LIST_OFF: style_list = 0;
pub type style_align = u32;
pub const STYLE_ALIGN_ABSOLUTE_CENTRE: style_align = 4;
pub const STYLE_ALIGN_RIGHT: style_align = 3;
pub const STYLE_ALIGN_CENTRE: style_align = 2;
pub const STYLE_ALIGN_LEFT: style_align = 1;
pub const STYLE_ALIGN_DEFAULT: style_align = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_cell {
    pub data: utf8_data,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub tqh_first: *mut window_mode_entry,
    pub tqh_last: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode_entry {
    pub wp: *mut window_pane,
    pub swp: *mut window_pane,
    pub mode: *const window_mode,
    pub data: *mut libc::c_void,
    pub screen: *mut screen,
    pub prefix: u_int,
    pub entry: C2RustUnnamed_16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub tqe_next: *mut window_mode_entry,
    pub tqe_prev: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen {
    pub title: *mut i8,
    pub path: *mut i8,
    pub titles: *mut screen_titles,
    pub grid: *mut grid,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub default_cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub default_ccolour: i32,
    pub rupper: u_int,
    pub rlower: u_int,
    pub mode: i32,
    pub default_mode: i32,
    pub saved_cx: u_int,
    pub saved_cy: u_int,
    pub saved_grid: *mut grid,
    pub saved_cell: grid_cell,
    pub saved_flags: i32,
    pub tabs: *mut bitstr_t,
    pub sel: *mut screen_sel,
    pub write_list: *mut screen_write_cline,
    pub hyperlinks: *mut hyperlinks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid {
    pub flags: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub hscrolled: u_int,
    pub hsize: u_int,
    pub hlimit: u_int,
    pub linedata: *mut grid_line,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_line {
    pub celldata: *mut grid_cell_entry,
    pub cellused: u_int,
    pub cellsize: u_int,
    pub extddata: *mut grid_extd_entry,
    pub extdsize: u_int,
    pub flags: i32,
    pub time: time_t,
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_extd_entry {
    pub data: utf8_char,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
pub type utf8_char = u_int;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_cell_entry {
    pub c2rust_unnamed: C2RustUnnamed_17,
    pub flags: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_17 {
    pub offset: u_int,
    pub data: C2RustUnnamed_18,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub attr: u_char,
    pub fg: u_char,
    pub bg: u_char,
    pub data: u_char,
}
pub type screen_cursor_style = u32;
pub const SCREEN_CURSOR_BAR: screen_cursor_style = 3;
pub const SCREEN_CURSOR_UNDERLINE: screen_cursor_style = 2;
pub const SCREEN_CURSOR_BLOCK: screen_cursor_style = 1;
pub const SCREEN_CURSOR_DEFAULT: screen_cursor_style = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode {
    pub name: *const i8,
    pub default_format: *const i8,
    pub init: Option<
        unsafe extern "C" fn(*mut window_mode_entry, *mut cmd_find_state, *mut args) -> *mut screen,
    >,
    pub free: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub resize: Option<unsafe extern "C" fn(*mut window_mode_entry, u_int, u_int) -> ()>,
    pub update: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub key: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            key_code,
            *mut mouse_event,
        ) -> (),
    >,
    pub key_table: Option<unsafe extern "C" fn(*mut window_mode_entry) -> *const i8>,
    pub command: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            *mut args,
            *mut mouse_event,
        ) -> (),
    >,
    pub formats: Option<unsafe extern "C" fn(*mut window_mode_entry, *mut format_tree) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct mouse_event {
    pub valid: i32,
    pub ignore: i32,
    pub key: key_code,
    pub statusat: i32,
    pub statuslines: u_int,
    pub x: u_int,
    pub y: u_int,
    pub b: u_int,
    pub lx: u_int,
    pub ly: u_int,
    pub lb: u_int,
    pub ox: u_int,
    pub oy: u_int,
    pub s: i32,
    pub w: i32,
    pub wp: i32,
    pub sgr_type: u_int,
    pub sgr_b: u_int,
}
pub type key_code = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink {
    pub idx: i32,
    pub session: *mut session,
    pub window: *mut window,
    pub flags: i32,
    pub entry: C2RustUnnamed_21,
    pub wentry: C2RustUnnamed_20,
    pub sentry: C2RustUnnamed_19,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_19 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_21 {
    pub rbe_left: *mut winlink,
    pub rbe_right: *mut winlink,
    pub rbe_parent: *mut winlink,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window {
    pub id: u_int,
    pub latest: *mut libc::c_void,
    pub name: *mut i8,
    pub name_event: event,
    pub name_time: timeval,
    pub alerts_timer: event,
    pub offset_timer: event,
    pub activity_time: timeval,
    pub active: *mut window_pane,
    pub last_panes: window_panes,
    pub panes: window_panes,
    pub lastlayout: i32,
    pub layout_root: *mut layout_cell,
    pub saved_layout_root: *mut layout_cell,
    pub old_layout: *mut i8,
    pub sx: u_int,
    pub sy: u_int,
    pub manual_sx: u_int,
    pub manual_sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub new_sx: u_int,
    pub new_sy: u_int,
    pub new_xpixel: u_int,
    pub new_ypixel: u_int,
    pub fill_character: *mut utf8_data,
    pub flags: i32,
    pub alerts_queued: i32,
    pub alerts_entry: C2RustUnnamed_24,
    pub options: *mut options,
    pub references: u_int,
    pub winlinks: C2RustUnnamed_23,
    pub entry: C2RustUnnamed_22,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_22 {
    pub rbe_left: *mut window,
    pub rbe_right: *mut window,
    pub rbe_parent: *mut window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_23 {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_24 {
    pub tqe_next: *mut window,
    pub tqe_prev: *mut *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cell {
    pub type_0: layout_type,
    pub parent: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub wp: *mut window_pane,
    pub cells: layout_cells,
    pub entry: C2RustUnnamed_25,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_25 {
    pub tqe_next: *mut layout_cell,
    pub tqe_prev: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cells {
    pub tqh_first: *mut layout_cell,
    pub tqh_last: *mut *mut layout_cell,
}
pub type layout_type = u32;
pub const LAYOUT_WINDOWPANE: layout_type = 2;
pub const LAYOUT_TOPBOTTOM: layout_type = 1;
pub const LAYOUT_LEFTRIGHT: layout_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_panes {
    pub tqh_first: *mut window_pane,
    pub tqh_last: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct session {
    pub id: u_int,
    pub name: *mut i8,
    pub cwd: *const i8,
    pub creation_time: timeval,
    pub last_attached_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub lock_timer: event,
    pub curw: *mut winlink,
    pub lastw: winlink_stack,
    pub windows: winlinks,
    pub statusat: i32,
    pub statuslines: u_int,
    pub options: *mut options,
    pub flags: i32,
    pub attached: u_int,
    pub tio: *mut termios,
    pub environ: *mut environ,
    pub references: i32,
    pub gentry: C2RustUnnamed_27,
    pub entry: C2RustUnnamed_26,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_26 {
    pub rbe_left: *mut session,
    pub rbe_right: *mut session,
    pub rbe_parent: *mut session,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_27 {
    pub tqe_next: *mut session,
    pub tqe_prev: *mut *mut session,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlinks {
    pub rbh_root: *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink_stack {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client {
    pub name: *const i8,
    pub peer: *mut tmuxpeer,
    pub queue: *mut cmdq_list,
    pub windows: client_windows,
    pub control_state: *mut control_state,
    pub pause_age: u_int,
    pub pid: pid_t,
    pub fd: i32,
    pub out_fd: i32,
    pub event: event,
    pub retval: i32,
    pub creation_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub environ: *mut environ,
    pub jobs: *mut format_job_tree,
    pub title: *mut i8,
    pub path: *mut i8,
    pub cwd: *const i8,
    pub term_name: *mut i8,
    pub term_features: i32,
    pub term_type: *mut i8,
    pub term_caps: *mut *mut i8,
    pub term_ncaps: u_int,
    pub ttyname: *mut i8,
    pub tty: tty,
    pub written: size_t,
    pub discarded: size_t,
    pub redraw: size_t,
    pub repeat_timer: event,
    pub click_timer: event,
    pub click_button: u_int,
    pub click_event: mouse_event,
    pub status: status_line,
    pub flags: uint64_t,
    pub exit_type: C2RustUnnamed_33,
    pub exit_msgtype: msgtype,
    pub exit_session: *mut i8,
    pub exit_message: *mut i8,
    pub keytable: *mut key_table,
    pub last_key: key_code,
    pub redraw_panes: uint64_t,
    pub redraw_scrollbars: uint64_t,
    pub message_ignore_keys: i32,
    pub message_ignore_styles: i32,
    pub message_string: *mut i8,
    pub message_timer: event,
    pub prompt_string: *mut i8,
    pub prompt_buffer: *mut utf8_data,
    pub prompt_last: *mut i8,
    pub prompt_index: size_t,
    pub prompt_inputcb: prompt_input_cb,
    pub prompt_freecb: prompt_free_cb,
    pub prompt_data: *mut libc::c_void,
    pub prompt_hindex: [u_int; 4],
    pub prompt_mode: C2RustUnnamed_30,
    pub prompt_saved: *mut utf8_data,
    pub prompt_flags: i32,
    pub prompt_type: prompt_type,
    pub prompt_cursor: i32,
    pub session: *mut session,
    pub last_session: *mut session,
    pub references: i32,
    pub pan_window: *mut libc::c_void,
    pub pan_ox: u_int,
    pub pan_oy: u_int,
    pub overlay_check: overlay_check_cb,
    pub overlay_mode: overlay_mode_cb,
    pub overlay_draw: overlay_draw_cb,
    pub overlay_key: overlay_key_cb,
    pub overlay_free: overlay_free_cb,
    pub overlay_resize: overlay_resize_cb,
    pub overlay_data: *mut libc::c_void,
    pub overlay_timer: event,
    pub files: client_files,
    pub clipboard_panes: *mut u_int,
    pub clipboard_npanes: u_int,
    pub entry: C2RustUnnamed_28,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_28 {
    pub tqe_next: *mut client,
    pub tqe_prev: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_files {
    pub rbh_root: *mut client_file,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_file {
    pub c: *mut client,
    pub peer: *mut tmuxpeer,
    pub tree: *mut client_files,
    pub references: i32,
    pub stream: i32,
    pub path: *mut i8,
    pub buffer: *mut evbuffer,
    pub event: *mut bufferevent,
    pub fd: i32,
    pub error: i32,
    pub closed: i32,
    pub cb: client_file_cb,
    pub data: *mut libc::c_void,
    pub entry: C2RustUnnamed_29,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_29 {
    pub rbe_left: *mut client_file,
    pub rbe_right: *mut client_file,
    pub rbe_parent: *mut client_file,
    pub rbe_color: i32,
}
pub type client_file_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *const i8,
        i32,
        i32,
        *mut evbuffer,
        *mut libc::c_void,
    ) -> (),
>;
pub type overlay_resize_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_free_cb = Option<unsafe extern "C" fn(*mut client, *mut libc::c_void) -> ()>;
pub type overlay_key_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut key_event) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_event {
    pub key: key_code,
    pub m: mouse_event,
    pub buf: *mut i8,
    pub len: size_t,
}
pub type overlay_draw_cb =
    Option<unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut screen_redraw_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_redraw_ctx {
    pub c: *mut client,
    pub statuslines: u_int,
    pub statustop: i32,
    pub pane_status: i32,
    pub pane_lines: pane_lines,
    pub pane_scrollbars: i32,
    pub pane_scrollbars_pos: i32,
    pub no_pane_gc: grid_cell,
    pub no_pane_gc_set: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub ox: u_int,
    pub oy: u_int,
}
pub type pane_lines = u32;
pub const PANE_LINES_NUMBER: pane_lines = 4;
pub const PANE_LINES_SIMPLE: pane_lines = 3;
pub const PANE_LINES_HEAVY: pane_lines = 2;
pub const PANE_LINES_DOUBLE: pane_lines = 1;
pub const PANE_LINES_SINGLE: pane_lines = 0;
pub type overlay_mode_cb = Option<
    unsafe extern "C" fn(*mut client, *mut libc::c_void, *mut u_int, *mut u_int) -> *mut screen,
>;
pub type overlay_check_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut libc::c_void,
        u_int,
        u_int,
        u_int,
        *mut overlay_ranges,
    ) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct overlay_ranges {
    pub px: [u_int; 3],
    pub nx: [u_int; 3],
}
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type C2RustUnnamed_30 = u32;
pub const PROMPT_COMMAND: C2RustUnnamed_30 = 1;
pub const PROMPT_ENTRY: C2RustUnnamed_30 = 0;
pub type prompt_free_cb = Option<unsafe extern "C" fn(*mut libc::c_void) -> ()>;
pub type prompt_input_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut libc::c_void,
        *const i8,
        i32,
    ) -> i32,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed_31,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_31 {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_32 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
pub type C2RustUnnamed_33 = u32;
pub const CLIENT_EXIT_DETACH: C2RustUnnamed_33 = 2;
pub const CLIENT_EXIT_SHUTDOWN: C2RustUnnamed_33 = 1;
pub const CLIENT_EXIT_RETURN: C2RustUnnamed_33 = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line {
    pub timer: event,
    pub screen: screen,
    pub active: *mut screen,
    pub references: i32,
    pub style: grid_cell,
    pub entries: [status_line_entry; 5],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line_entry {
    pub expanded: *mut i8,
    pub ranges: style_ranges,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_ranges {
    pub tqh_first: *mut style_range,
    pub tqh_last: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_range {
    pub type_0: style_range_type,
    pub argument: u_int,
    pub string: [i8; 16],
    pub start: u_int,
    pub end: u_int,
    pub entry: C2RustUnnamed_34,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_34 {
    pub tqe_next: *mut style_range,
    pub tqe_prev: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty {
    pub client: *mut client,
    pub start_timer: event,
    pub clipboard_timer: event,
    pub last_requests: time_t,
    pub sx: u_int,
    pub sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub oflag: i32,
    pub oox: u_int,
    pub ooy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub mode: i32,
    pub fg: i32,
    pub bg: i32,
    pub rlower: u_int,
    pub rupper: u_int,
    pub rleft: u_int,
    pub rright: u_int,
    pub event_in: event,
    pub in_0: *mut evbuffer,
    pub event_out: event,
    pub out: *mut evbuffer,
    pub timer: event,
    pub discarded: size_t,
    pub tio: termios,
    pub cell: grid_cell,
    pub last_cell: grid_cell,
    pub flags: i32,
    pub term: *mut tty_term,
    pub mouse_last_x: u_int,
    pub mouse_last_y: u_int,
    pub mouse_last_b: u_int,
    pub mouse_drag_flag: i32,
    pub mouse_scrolling_flag: i32,
    pub mouse_slider_mpos: i32,
    pub mouse_drag_update: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub mouse_drag_release: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub key_timer: event,
    pub key_tree: *mut tty_key,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_term {
    pub name: *mut i8,
    pub tty: *mut tty,
    pub features: i32,
    pub acs: [[i8; 2]; 256],
    pub codes: *mut tty_code,
    pub flags: i32,
    pub entry: C2RustUnnamed_35,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_35 {
    pub le_next: *mut tty_term,
    pub le_prev: *mut *mut tty_term,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_windows {
    pub rbh_root: *mut client_window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_window {
    pub window: u_int,
    pub pane: *mut window_pane,
    pub sx: u_int,
    pub sy: u_int,
    pub entry: C2RustUnnamed_36,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_36 {
    pub rbe_left: *mut client_window,
    pub rbe_right: *mut client_window,
    pub rbe_parent: *mut client_window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_offset {
    pub used: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct colour_palette {
    pub fg: i32,
    pub bg: i32,
    pub palette: *mut i32,
    pub default_palette: *mut i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resizes {
    pub tqh_first: *mut window_pane_resize,
    pub tqh_last: *mut *mut window_pane_resize,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resize {
    pub sx: u_int,
    pub sy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub entry: C2RustUnnamed_37,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_37 {
    pub tqe_next: *mut window_pane_resize,
    pub tqe_prev: *mut *mut window_pane_resize,
}
pub type args_parse_type = u32;
pub const ARGS_PARSE_COMMANDS: args_parse_type = 3;
pub const ARGS_PARSE_COMMANDS_OR_STRING: args_parse_type = 2;
pub const ARGS_PARSE_STRING: args_parse_type = 1;
pub const ARGS_PARSE_INVALID: args_parse_type = 0;
pub type args_parse_cb =
    Option<unsafe extern "C" fn(*mut args, u_int, *mut *mut i8) -> args_parse_type>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_parse {
    pub template: *const i8,
    pub lower: i32,
    pub upper: i32,
    pub cb: args_parse_cb,
}
pub type cmd_find_type = u32;
pub const CMD_FIND_SESSION: cmd_find_type = 2;
pub const CMD_FIND_WINDOW: cmd_find_type = 1;
pub const CMD_FIND_PANE: cmd_find_type = 0;
pub type cmd_retval = i32;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
pub type cmd_parse_status = u32;
pub const CMD_PARSE_SUCCESS: cmd_parse_status = 1;
pub const CMD_PARSE_ERROR: cmd_parse_status = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_result {
    pub status: cmd_parse_status,
    pub cmdlist: *mut cmd_list,
    pub error: *mut i8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry_flag {
    pub flag: i8,
    pub type_0: cmd_find_type,
    pub flags: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry {
    pub name: *const i8,
    pub alias: *const i8,
    pub args: args_parse,
    pub usage: *const i8,
    pub source: cmd_entry_flag,
    pub target: cmd_entry_flag,
    pub flags: i32,
    pub exec: Option<unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval>,
}
unsafe extern "C" fn args_tree_RB_REMOVE(
    mut head: *mut args_tree,
    mut elm: *mut args_entry,
) -> *mut args_entry {
    let mut current_block: u64;
    let mut child: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut parent: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut old: *mut args_entry = elm;
    let mut color: i32 = 0;
    if ((*elm).entry.rbe_left).is_null() {
        child = (*elm).entry.rbe_right;
        current_block = 7245201122033322888;
    } else if ((*elm).entry.rbe_right).is_null() {
        child = (*elm).entry.rbe_left;
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut args_entry = std::ptr::null_mut::<args_entry>();
        elm = (*elm).entry.rbe_right;
        loop {
            left = (*elm).entry.rbe_left;
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = (*elm).entry.rbe_right;
        parent = (*elm).entry.rbe_parent;
        color = (*elm).entry.rbe_color;
        if !child.is_null() {
            (*child).entry.rbe_parent = parent;
        }
        if !parent.is_null() {
            if (*parent).entry.rbe_left == elm {
                (*parent).entry.rbe_left = child;
            } else {
                (*parent).entry.rbe_right = child;
            }
        } else {
            (*head).rbh_root = child;
        }
        if (*elm).entry.rbe_parent == old {
            parent = elm;
        }
        (*elm).entry = (*old).entry;
        if !((*old).entry.rbe_parent).is_null() {
            if (*(*old).entry.rbe_parent).entry.rbe_left == old {
                (*(*old).entry.rbe_parent).entry.rbe_left = elm;
            } else {
                (*(*old).entry.rbe_parent).entry.rbe_right = elm;
            }
        } else {
            (*head).rbh_root = elm;
        }
        (*(*old).entry.rbe_left).entry.rbe_parent = elm;
        if !((*old).entry.rbe_right).is_null() {
            (*(*old).entry.rbe_right).entry.rbe_parent = elm;
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = (*left).entry.rbe_parent;
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 12024256237142809034;
    }
    match current_block {
        7245201122033322888 => {
            parent = (*elm).entry.rbe_parent;
            color = (*elm).entry.rbe_color;
            if !child.is_null() {
                (*child).entry.rbe_parent = parent;
            }
            if !parent.is_null() {
                if (*parent).entry.rbe_left == elm {
                    (*parent).entry.rbe_left = child;
                } else {
                    (*parent).entry.rbe_right = child;
                }
            } else {
                (*head).rbh_root = child;
            }
        }
        _ => {}
    }
    if color == 0 as i32 {
        args_tree_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
unsafe extern "C" fn args_tree_RB_INSERT(
    mut head: *mut args_tree,
    mut elm: *mut args_entry,
) -> *mut args_entry {
    let mut tmp: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut parent: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut comp: i32 = 0 as i32;
    tmp = (*head).rbh_root;
    while !tmp.is_null() {
        parent = tmp;
        comp = args_cmp(elm, parent);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    (*elm).entry.rbe_parent = parent;
    (*elm).entry.rbe_right = std::ptr::null_mut::<args_entry>();
    (*elm).entry.rbe_left = (*elm).entry.rbe_right;
    (*elm).entry.rbe_color = 1 as i32;
    if !parent.is_null() {
        if comp < 0 as i32 {
            (*parent).entry.rbe_left = elm;
        } else {
            (*parent).entry.rbe_right = elm;
        }
    } else {
        (*head).rbh_root = elm;
    }
    args_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<args_entry>();
}
unsafe extern "C" fn args_tree_RB_MINMAX(
    mut head: *mut args_tree,
    mut val: i32,
) -> *mut args_entry {
    let mut tmp: *mut args_entry = (*head).rbh_root;
    let mut parent: *mut args_entry = std::ptr::null_mut::<args_entry>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else {
            tmp = (*tmp).entry.rbe_right;
        }
    }
    return parent;
}
unsafe extern "C" fn args_tree_RB_NEXT(mut elm: *mut args_entry) -> *mut args_entry {
    if !((*elm).entry.rbe_right).is_null() {
        elm = (*elm).entry.rbe_right;
        while !((*elm).entry.rbe_left).is_null() {
            elm = (*elm).entry.rbe_left;
        }
    } else if !((*elm).entry.rbe_parent).is_null()
        && elm == (*(*elm).entry.rbe_parent).entry.rbe_left
    {
        elm = (*elm).entry.rbe_parent;
    } else {
        while !((*elm).entry.rbe_parent).is_null()
            && elm == (*(*elm).entry.rbe_parent).entry.rbe_right
        {
            elm = (*elm).entry.rbe_parent;
        }
        elm = (*elm).entry.rbe_parent;
    }
    return elm;
}
unsafe extern "C" fn args_tree_RB_REMOVE_COLOR(
    mut head: *mut args_tree,
    mut parent: *mut args_entry,
    mut elm: *mut args_entry,
) {
    let mut tmp: *mut args_entry = std::ptr::null_mut::<args_entry>();
    while (elm.is_null() || (*elm).entry.rbe_color == 0 as i32) && elm != (*head).rbh_root {
        if (*parent).entry.rbe_left == elm {
            tmp = (*parent).entry.rbe_right;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_right;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32
                {
                    let mut oleft: *mut args_entry = std::ptr::null_mut::<args_entry>();
                    oleft = (*tmp).entry.rbe_left;
                    if !oleft.is_null() {
                        (*oleft).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oleft = (*tmp).entry.rbe_left;
                    (*tmp).entry.rbe_left = (*oleft).entry.rbe_right;
                    if !((*tmp).entry.rbe_left).is_null() {
                        (*(*oleft).entry.rbe_right).entry.rbe_parent = tmp;
                    }
                    (*oleft).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oleft).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oleft;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oleft;
                        }
                    } else {
                        (*head).rbh_root = oleft;
                    }
                    (*oleft).entry.rbe_right = tmp;
                    (*tmp).entry.rbe_parent = oleft;
                    !((*oleft).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_right;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_right;
                (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*parent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        } else {
            tmp = (*parent).entry.rbe_left;
            if (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 1 as i32;
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                tmp = (*parent).entry.rbe_left;
            }
            if (((*tmp).entry.rbe_left).is_null()
                || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32)
                && (((*tmp).entry.rbe_right).is_null()
                    || (*(*tmp).entry.rbe_right).entry.rbe_color == 0 as i32)
            {
                (*tmp).entry.rbe_color = 1 as i32;
                elm = parent;
                parent = (*elm).entry.rbe_parent;
            } else {
                if ((*tmp).entry.rbe_left).is_null()
                    || (*(*tmp).entry.rbe_left).entry.rbe_color == 0 as i32
                {
                    let mut oright: *mut args_entry = std::ptr::null_mut::<args_entry>();
                    oright = (*tmp).entry.rbe_right;
                    if !oright.is_null() {
                        (*oright).entry.rbe_color = 0 as i32;
                    }
                    (*tmp).entry.rbe_color = 1 as i32;
                    oright = (*tmp).entry.rbe_right;
                    (*tmp).entry.rbe_right = (*oright).entry.rbe_left;
                    if !((*tmp).entry.rbe_right).is_null() {
                        (*(*oright).entry.rbe_left).entry.rbe_parent = tmp;
                    }
                    (*oright).entry.rbe_parent = (*tmp).entry.rbe_parent;
                    if !((*oright).entry.rbe_parent).is_null() {
                        if tmp == (*(*tmp).entry.rbe_parent).entry.rbe_left {
                            (*(*tmp).entry.rbe_parent).entry.rbe_left = oright;
                        } else {
                            (*(*tmp).entry.rbe_parent).entry.rbe_right = oright;
                        }
                    } else {
                        (*head).rbh_root = oright;
                    }
                    (*oright).entry.rbe_left = tmp;
                    (*tmp).entry.rbe_parent = oright;
                    !((*oright).entry.rbe_parent).is_null();
                    tmp = (*parent).entry.rbe_left;
                }
                (*tmp).entry.rbe_color = (*parent).entry.rbe_color;
                (*parent).entry.rbe_color = 0 as i32;
                if !((*tmp).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_color = 0 as i32;
                }
                tmp = (*parent).entry.rbe_left;
                (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*parent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                }
                (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                        (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = parent;
                (*parent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
                elm = (*head).rbh_root;
                break;
            }
        }
    }
    if !elm.is_null() {
        (*elm).entry.rbe_color = 0 as i32;
    }
}
unsafe extern "C" fn args_tree_RB_FIND(
    mut head: *mut args_tree,
    mut elm: *mut args_entry,
) -> *mut args_entry {
    let mut tmp: *mut args_entry = (*head).rbh_root;
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = args_cmp(elm, tmp);
        if comp < 0 as i32 {
            tmp = (*tmp).entry.rbe_left;
        } else if comp > 0 as i32 {
            tmp = (*tmp).entry.rbe_right;
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<args_entry>();
}
unsafe extern "C" fn args_tree_RB_INSERT_COLOR(mut head: *mut args_tree, mut elm: *mut args_entry) {
    let mut parent: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut gparent: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut tmp: *mut args_entry = std::ptr::null_mut::<args_entry>();
    loop {
        parent = (*elm).entry.rbe_parent;
        if parent.is_null() || (*parent).entry.rbe_color != 1 as i32 {
            break;
        }
        gparent = (*parent).entry.rbe_parent;
        if parent == (*gparent).entry.rbe_left {
            tmp = (*gparent).entry.rbe_right;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_right == elm {
                    tmp = (*parent).entry.rbe_right;
                    (*parent).entry.rbe_right = (*tmp).entry.rbe_left;
                    if !((*parent).entry.rbe_right).is_null() {
                        (*(*tmp).entry.rbe_left).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_left = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_left;
                (*gparent).entry.rbe_left = (*tmp).entry.rbe_right;
                if !((*gparent).entry.rbe_left).is_null() {
                    (*(*tmp).entry.rbe_right).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_right = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        } else {
            tmp = (*gparent).entry.rbe_left;
            if !tmp.is_null() && (*tmp).entry.rbe_color == 1 as i32 {
                (*tmp).entry.rbe_color = 0 as i32;
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                elm = gparent;
            } else {
                if (*parent).entry.rbe_left == elm {
                    tmp = (*parent).entry.rbe_left;
                    (*parent).entry.rbe_left = (*tmp).entry.rbe_right;
                    if !((*parent).entry.rbe_left).is_null() {
                        (*(*tmp).entry.rbe_right).entry.rbe_parent = parent;
                    }
                    (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent;
                    if !((*tmp).entry.rbe_parent).is_null() {
                        if parent == (*(*parent).entry.rbe_parent).entry.rbe_left {
                            (*(*parent).entry.rbe_parent).entry.rbe_left = tmp;
                        } else {
                            (*(*parent).entry.rbe_parent).entry.rbe_right = tmp;
                        }
                    } else {
                        (*head).rbh_root = tmp;
                    }
                    (*tmp).entry.rbe_right = parent;
                    (*parent).entry.rbe_parent = tmp;
                    !((*tmp).entry.rbe_parent).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (*parent).entry.rbe_color = 0 as i32;
                (*gparent).entry.rbe_color = 1 as i32;
                tmp = (*gparent).entry.rbe_right;
                (*gparent).entry.rbe_right = (*tmp).entry.rbe_left;
                if !((*gparent).entry.rbe_right).is_null() {
                    (*(*tmp).entry.rbe_left).entry.rbe_parent = gparent;
                }
                (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent;
                if !((*tmp).entry.rbe_parent).is_null() {
                    if gparent == (*(*gparent).entry.rbe_parent).entry.rbe_left {
                        (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp;
                    } else {
                        (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp;
                    }
                } else {
                    (*head).rbh_root = tmp;
                }
                (*tmp).entry.rbe_left = gparent;
                (*gparent).entry.rbe_parent = tmp;
                !((*tmp).entry.rbe_parent).is_null();
            }
        }
    }
    (*(*head).rbh_root).entry.rbe_color = 0 as i32;
}
unsafe extern "C" fn args_cmp(mut a1: *mut args_entry, mut a2: *mut args_entry) -> i32 {
    return (*a1).flag as i32 - (*a2).flag as i32;
}
unsafe extern "C" fn args_find(mut args: *mut args, mut flag: u_char) -> *mut args_entry {
    let mut entry: args_entry = args_entry {
        flag: 0,
        values: args_values {
            tqh_first: std::ptr::null_mut::<args_value>(),
            tqh_last: std::ptr::null_mut::<*mut args_value>(),
        },
        count: 0,
        flags: 0,
        entry: C2RustUnnamed_11 {
            rbe_left: std::ptr::null_mut::<args_entry>(),
            rbe_right: std::ptr::null_mut::<args_entry>(),
            rbe_parent: std::ptr::null_mut::<args_entry>(),
            rbe_color: 0,
        },
    };
    entry.flag = flag;
    return args_tree_RB_FIND(&mut (*args).tree, &mut entry);
}
unsafe extern "C" fn args_copy_value(mut to: *mut args_value, mut from: *mut args_value) {
    (*to).type_0 = (*from).type_0;
    match (*from).type_0 as u32 {
        2 => {
            (*to).c2rust_unnamed.cmdlist = (*from).c2rust_unnamed.cmdlist;
            (*(*to).c2rust_unnamed.cmdlist).references += 1;
        }
        1 => {
            (*to).c2rust_unnamed.string = xstrdup((*from).c2rust_unnamed.string);
        }
        0 | _ => {}
    };
}
unsafe extern "C" fn args_type_to_string(mut type_0: args_type) -> *const i8 {
    match type_0 as u32 {
        0 => return b"NONE\0" as *const u8 as *const i8,
        1 => return b"STRING\0" as *const u8 as *const i8,
        2 => return b"COMMANDS\0" as *const u8 as *const i8,
        _ => {}
    }
    return b"INVALID\0" as *const u8 as *const i8;
}
unsafe extern "C" fn args_value_as_string(mut value: *mut args_value) -> *const i8 {
    match (*value).type_0 as u32 {
        0 => return b"\0" as *const u8 as *const i8,
        2 => {
            if ((*value).cached).is_null() {
                (*value).cached = cmd_list_print((*value).c2rust_unnamed.cmdlist, 0 as i32);
            }
            return (*value).cached;
        }
        1 => return (*value).c2rust_unnamed.string,
        _ => {}
    }
    fatalx(b"unexpected argument type\0" as *const u8 as *const i8);
}
#[no_mangle]
pub unsafe extern "C" fn args_create() -> *mut args {
    let mut args: *mut args = std::ptr::null_mut::<args>();
    args = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<args>() as u64,
    ) as *mut args;
    (*args).tree.rbh_root = std::ptr::null_mut::<args_entry>();
    return args;
}
unsafe extern "C" fn args_parse_flag_argument(
    mut values: *mut args_value,
    mut count: u_int,
    mut cause: *mut *mut i8,
    mut args: *mut args,
    mut i: *mut u_int,
    mut string: *const i8,
    mut flag: i32,
    mut optional_argument: i32,
) -> i32 {
    let mut argument: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut new: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut s: *const i8 = std::ptr::null::<i8>();
    new = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<args_value>() as u64,
    ) as *mut args_value;
    if *string as i32 != '\0' as i32 {
        (*new).type_0 = ARGS_STRING;
        (*new).c2rust_unnamed.string = xstrdup(string);
    } else {
        if *i == count {
            argument = std::ptr::null_mut::<args_value>();
        } else {
            argument = &mut *values.offset(*i as isize) as *mut args_value;
            if (*argument).type_0 as u32 != ARGS_STRING as i32 as u32 {
                xasprintf(
                    cause,
                    b"-%c argument must be a string\0" as *const u8 as *const i8,
                    flag,
                );
                args_free_value(new);
                free(new as *mut libc::c_void);
                return -(1 as i32);
            }
        }
        if argument.is_null() {
            args_free_value(new);
            free(new as *mut libc::c_void);
            if optional_argument != 0 {
                log_debug(
                    b"%s: -%c (optional)\0" as *const u8 as *const i8,
                    (*::core::mem::transmute::<&[u8; 25], &[i8; 25]>(
                        b"args_parse_flag_argument\0",
                    ))
                    .as_ptr(),
                    flag,
                );
                args_set(
                    args,
                    flag as u_char,
                    std::ptr::null_mut::<args_value>(),
                    0x1 as i32,
                );
                return 0 as i32;
            }
            xasprintf(
                cause,
                b"-%c expects an argument\0" as *const u8 as *const i8,
                flag,
            );
            return -(1 as i32);
        }
        args_copy_value(new, argument);
        *i = (*i).wrapping_add(1);
    }
    s = args_value_as_string(new);
    log_debug(
        b"%s: -%c = %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 25], &[i8; 25]>(b"args_parse_flag_argument\0"))
            .as_ptr(),
        flag,
        s,
    );
    args_set(args, flag as u_char, new, 0 as i32);
    return 0 as i32;
}
unsafe extern "C" fn args_parse_flags(
    mut parse: *const args_parse,
    mut values: *mut args_value,
    mut count: u_int,
    mut cause: *mut *mut i8,
    mut args: *mut args,
    mut i: *mut u_int,
) -> i32 {
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut flag: u_char = 0;
    let mut found: *const i8 = std::ptr::null::<i8>();
    let mut string: *const i8 = std::ptr::null::<i8>();
    let mut optional_argument: i32 = 0;
    value = &mut *values.offset(*i as isize) as *mut args_value;
    if (*value).type_0 as u32 != ARGS_STRING as i32 as u32 {
        return 1 as i32;
    }
    string = (*value).c2rust_unnamed.string;
    log_debug(
        b"%s: next %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 17], &[i8; 17]>(b"args_parse_flags\0")).as_ptr(),
        string,
    );
    let fresh0 = string;
    string = string.offset(1);
    if *fresh0 as i32 != '-' as i32 || *string as i32 == '\0' as i32 {
        return 1 as i32;
    }
    *i = (*i).wrapping_add(1);
    if *string.offset(0 as i32 as isize) as i32 == '-' as i32
        && *string.offset(1 as i32 as isize) as i32 == '\0' as i32
    {
        return 1 as i32;
    }
    loop {
        let fresh1 = string;
        string = string.offset(1);
        flag = *fresh1 as u_char;
        if flag as i32 == '\0' as i32 {
            return 0 as i32;
        }
        if flag as i32 == '?' as i32 {
            return -(1 as i32);
        }
        if *(*__ctype_b_loc()).offset(flag as i32 as isize) as i32
            & _ISalnum as i32 as u16 as i32
            == 0
        {
            xasprintf(
                cause,
                b"invalid flag -%c\0" as *const u8 as *const i8,
                flag as i32,
            );
            return -(1 as i32);
        }
        found = strchr((*parse).template, flag as i32);
        if found.is_null() {
            xasprintf(
                cause,
                b"unknown flag -%c\0" as *const u8 as *const i8,
                flag as i32,
            );
            return -(1 as i32);
        }
        if *found.offset(1 as i32 as isize) as i32 != ':' as i32 {
            log_debug(
                b"%s: -%c\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 17], &[i8; 17]>(b"args_parse_flags\0"))
                    .as_ptr(),
                flag as i32,
            );
            args_set(
                args,
                flag,
                std::ptr::null_mut::<args_value>(),
                0 as i32,
            );
        } else {
            optional_argument = (*found.offset(2 as i32 as isize) as i32
                == ':' as i32) as i32;
            return args_parse_flag_argument(
                values,
                count,
                cause,
                args,
                i,
                string,
                flag as i32,
                optional_argument,
            );
        }
    }
}
#[no_mangle]
pub unsafe extern "C" fn args_parse(
    mut parse: *const args_parse,
    mut values: *mut args_value,
    mut count: u_int,
    mut cause: *mut *mut i8,
) -> *mut args {
    let mut args: *mut args = std::ptr::null_mut::<args>();
    let mut i: u_int = 0;
    let mut type_0: args_parse_type = ARGS_PARSE_INVALID;
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut new: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut s: *const i8 = std::ptr::null::<i8>();
    let mut stop: i32 = 0;
    if count == 0 as i32 as u32 {
        return args_create();
    }
    args = args_create();
    i = 1 as i32 as u_int;
    while i < count {
        stop = args_parse_flags(parse, values, count, cause, args, &mut i);
        if stop == -(1 as i32) {
            args_free(args);
            return std::ptr::null_mut::<args>();
        }
        if stop == 1 as i32 {
            break;
        }
    }
    log_debug(
        b"%s: flags end at %u of %u\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b"args_parse\0")).as_ptr(),
        i,
        count,
    );
    if i != count {
        while i < count {
            value = &mut *values.offset(i as isize) as *mut args_value;
            s = args_value_as_string(value);
            log_debug(
                b"%s: %u = %s (type %s)\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b"args_parse\0"))
                    .as_ptr(),
                i,
                s,
                args_type_to_string((*value).type_0),
            );
            if ((*parse).cb).is_some() {
                type_0 =
                    ((*parse).cb).expect("non-null function pointer")(args, (*args).count, cause);
                if type_0 as u32 == ARGS_PARSE_INVALID as i32 as u32 {
                    args_free(args);
                    return std::ptr::null_mut::<args>();
                }
            } else {
                type_0 = ARGS_PARSE_STRING;
            }
            (*args).values = xrecallocarray(
                (*args).values as *mut libc::c_void,
                (*args).count as size_t,
                ((*args).count).wrapping_add(1 as i32 as u32) as size_t,
                ::core::mem::size_of::<args_value>() as u64,
            ) as *mut args_value;
            let fresh2 = (*args).count;
            (*args).count = ((*args).count).wrapping_add(1);
            new = &mut *((*args).values).offset(fresh2 as isize) as *mut args_value;
            match type_0 as u32 {
                0 => {
                    fatalx(b"unexpected argument type\0" as *const u8 as *const i8);
                }
                1 => {
                    if (*value).type_0 as u32 != ARGS_STRING as i32 as u32
                    {
                        xasprintf(
                            cause,
                            b"argument %u must be \"string\"\0" as *const u8 as *const i8,
                            (*args).count,
                        );
                        args_free(args);
                        return std::ptr::null_mut::<args>();
                    }
                    args_copy_value(new, value);
                }
                2 => {
                    args_copy_value(new, value);
                }
                3 => {
                    if (*value).type_0 as u32
                        != ARGS_COMMANDS as i32 as u32
                    {
                        xasprintf(
                            cause,
                            b"argument %u must be { commands }\0" as *const u8
                                as *const i8,
                            (*args).count,
                        );
                        args_free(args);
                        return std::ptr::null_mut::<args>();
                    }
                    args_copy_value(new, value);
                }
                _ => {}
            }
            i = i.wrapping_add(1);
        }
    }
    if (*parse).lower != -(1 as i32) && (*args).count < (*parse).lower as u_int {
        xasprintf(
            cause,
            b"too few arguments (need at least %u)\0" as *const u8 as *const i8,
            (*parse).lower,
        );
        args_free(args);
        return std::ptr::null_mut::<args>();
    }
    if (*parse).upper != -(1 as i32) && (*args).count > (*parse).upper as u_int {
        xasprintf(
            cause,
            b"too many arguments (need at most %u)\0" as *const u8 as *const i8,
            (*parse).upper,
        );
        args_free(args);
        return std::ptr::null_mut::<args>();
    }
    return args;
}
unsafe extern "C" fn args_copy_copy_value(
    mut to: *mut args_value,
    mut from: *mut args_value,
    mut argc: i32,
    mut argv: *mut *mut i8,
) {
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    let mut expanded: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: i32 = 0;
    (*to).type_0 = (*from).type_0;
    match (*from).type_0 as u32 {
        1 => {
            expanded = xstrdup((*from).c2rust_unnamed.string);
            i = 0 as i32;
            while i < argc {
                s = cmd_template_replace(expanded, *argv.offset(i as isize), i + 1 as i32);
                free(expanded as *mut libc::c_void);
                expanded = s;
                i += 1;
            }
            (*to).c2rust_unnamed.string = expanded;
        }
        2 => {
            (*to).c2rust_unnamed.cmdlist =
                cmd_list_copy((*from).c2rust_unnamed.cmdlist, argc, argv);
        }
        0 | _ => {}
    };
}
#[no_mangle]
pub unsafe extern "C" fn args_copy(
    mut args: *mut args,
    mut argc: i32,
    mut argv: *mut *mut i8,
) -> *mut args {
    let mut new_args: *mut args = std::ptr::null_mut::<args>();
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut new_value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut i: u_int = 0;
    cmd_log_argv(
        argc,
        argv,
        b"%s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 10], &[i8; 10]>(b"args_copy\0")).as_ptr(),
    );
    new_args = args_create();
    entry = args_tree_RB_MINMAX(&mut (*args).tree, -(1 as i32));
    while !entry.is_null() {
        if ((*entry).values.tqh_first).is_null() {
            i = 0 as i32 as u_int;
            while i < (*entry).count {
                args_set(
                    new_args,
                    (*entry).flag,
                    std::ptr::null_mut::<args_value>(),
                    0 as i32,
                );
                i = i.wrapping_add(1);
            }
        } else {
            value = (*entry).values.tqh_first;
            while !value.is_null() {
                new_value = xcalloc(
                    1 as i32 as size_t,
                    ::core::mem::size_of::<args_value>() as u64,
                ) as *mut args_value;
                args_copy_copy_value(new_value, value, argc, argv);
                args_set(new_args, (*entry).flag, new_value, 0 as i32);
                value = (*value).entry.tqe_next;
            }
        }
        entry = args_tree_RB_NEXT(entry);
    }
    if (*args).count == 0 as i32 as u32 {
        return new_args;
    }
    (*new_args).count = (*args).count;
    (*new_args).values = xcalloc(
        (*args).count as size_t,
        ::core::mem::size_of::<args_value>() as u64,
    ) as *mut args_value;
    i = 0 as i32 as u_int;
    while i < (*args).count {
        new_value = &mut *((*new_args).values).offset(i as isize) as *mut args_value;
        args_copy_copy_value(
            new_value,
            &mut *((*args).values).offset(i as isize),
            argc,
            argv,
        );
        i = i.wrapping_add(1);
    }
    return new_args;
}
#[no_mangle]
pub unsafe extern "C" fn args_free_value(mut value: *mut args_value) {
    match (*value).type_0 as u32 {
        1 => {
            free((*value).c2rust_unnamed.string as *mut libc::c_void);
        }
        2 => {
            cmd_list_free((*value).c2rust_unnamed.cmdlist);
        }
        0 | _ => {}
    }
    free((*value).cached as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn args_free_values(mut values: *mut args_value, mut count: u_int) {
    let mut i: u_int = 0;
    i = 0 as i32 as u_int;
    while i < count {
        args_free_value(&mut *values.offset(i as isize));
        i = i.wrapping_add(1);
    }
}
#[no_mangle]
pub unsafe extern "C" fn args_free(mut args: *mut args) {
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut entry1: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut value1: *mut args_value = std::ptr::null_mut::<args_value>();
    args_free_values((*args).values, (*args).count);
    free((*args).values as *mut libc::c_void);
    entry = args_tree_RB_MINMAX(&mut (*args).tree, -(1 as i32));
    while !entry.is_null() && {
        entry1 = args_tree_RB_NEXT(entry);
        1 as i32 != 0
    } {
        args_tree_RB_REMOVE(&mut (*args).tree, entry);
        value = (*entry).values.tqh_first;
        while !value.is_null() && {
            value1 = (*value).entry.tqe_next;
            1 as i32 != 0
        } {
            if !((*value).entry.tqe_next).is_null() {
                (*(*value).entry.tqe_next).entry.tqe_prev = (*value).entry.tqe_prev;
            } else {
                (*entry).values.tqh_last = (*value).entry.tqe_prev;
            }
            *(*value).entry.tqe_prev = (*value).entry.tqe_next;
            args_free_value(value);
            free(value as *mut libc::c_void);
            value = value1;
        }
        free(entry as *mut libc::c_void);
        entry = entry1;
    }
    free(args as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn args_to_vector(
    mut args: *mut args,
    mut argc: *mut i32,
    mut argv: *mut *mut *mut i8,
) {
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: u_int = 0;
    *argc = 0 as i32;
    *argv = std::ptr::null_mut::<*mut i8>();
    i = 0 as i32 as u_int;
    while i < (*args).count {
        match (*((*args).values).offset(i as isize)).type_0 as u32 {
            1 => {
                cmd_append_argv(
                    argc,
                    argv,
                    (*((*args).values).offset(i as isize)).c2rust_unnamed.string,
                );
            }
            2 => {
                s = cmd_list_print(
                    (*((*args).values).offset(i as isize))
                        .c2rust_unnamed
                        .cmdlist,
                    0 as i32,
                );
                cmd_append_argv(argc, argv, s);
                free(s as *mut libc::c_void);
            }
            0 | _ => {}
        }
        i = i.wrapping_add(1);
    }
}
#[no_mangle]
pub unsafe extern "C" fn args_from_vector(
    mut argc: i32,
    mut argv: *mut *mut i8,
) -> *mut args_value {
    let mut values: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut i: i32 = 0;
    values = xcalloc(
        argc as size_t,
        ::core::mem::size_of::<args_value>() as u64,
    ) as *mut args_value;
    i = 0 as i32;
    while i < argc {
        (*values.offset(i as isize)).type_0 = ARGS_STRING;
        let ref mut fresh3 = (*values.offset(i as isize)).c2rust_unnamed.string;
        *fresh3 = xstrdup(*argv.offset(i as isize));
        i += 1;
    }
    return values;
}
unsafe extern "C" fn args_print_add(
    mut buf: *mut *mut i8,
    mut len: *mut size_t,
    mut fmt: *const i8,
    mut args: ...
) {
    let mut ap: ::core::ffi::VaListImpl;
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    let mut slen: size_t = 0;
    ap = args.clone();
    slen = xvasprintf(&mut s, fmt, ap.as_va_list()) as size_t;
    *len = (*len as u64).wrapping_add(slen) as size_t as size_t;
    *buf = xrealloc(*buf as *mut libc::c_void, *len) as *mut i8;
    strlcat(*buf, s, *len);
    free(s as *mut libc::c_void);
}
unsafe extern "C" fn args_print_add_value(
    mut buf: *mut *mut i8,
    mut len: *mut size_t,
    mut value: *mut args_value,
) {
    let mut expanded: *mut i8 = std::ptr::null_mut::<i8>();
    if **buf as i32 != '\0' as i32 {
        args_print_add(buf, len, b" \0" as *const u8 as *const i8);
    }
    match (*value).type_0 as u32 {
        2 => {
            expanded = cmd_list_print((*value).c2rust_unnamed.cmdlist, 0 as i32);
            args_print_add(
                buf,
                len,
                b"{ %s }\0" as *const u8 as *const i8,
                expanded,
            );
        }
        1 => {
            expanded = args_escape((*value).c2rust_unnamed.string);
            args_print_add(
                buf,
                len,
                b"%s\0" as *const u8 as *const i8,
                expanded,
            );
        }
        0 | _ => {}
    }
    free(expanded as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn args_print(mut args: *mut args) -> *mut i8 {
    let mut len: size_t = 0;
    let mut buf: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: u_int = 0;
    let mut j: u_int = 0;
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut last: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    len = 1 as i32 as size_t;
    buf = xcalloc(1 as i32 as size_t, len) as *mut i8;
    entry = args_tree_RB_MINMAX(&mut (*args).tree, -(1 as i32));
    while !entry.is_null() {
        if (*entry).flags & 0x1 as i32 == 0 {
            if ((*entry).values.tqh_first).is_null() {
                if *buf as i32 == '\0' as i32 {
                    args_print_add(
                        &mut buf as *mut *mut i8,
                        &mut len as *mut size_t,
                        b"-\0" as *const u8 as *const i8,
                    );
                }
                j = 0 as i32 as u_int;
                while j < (*entry).count {
                    args_print_add(
                        &mut buf as *mut *mut i8,
                        &mut len as *mut size_t,
                        b"%c\0" as *const u8 as *const i8,
                        (*entry).flag as i32,
                    );
                    j = j.wrapping_add(1);
                }
            }
        }
        entry = args_tree_RB_NEXT(entry);
    }
    entry = args_tree_RB_MINMAX(&mut (*args).tree, -(1 as i32));
    while !entry.is_null() {
        if (*entry).flags & 0x1 as i32 != 0 {
            if *buf as i32 != '\0' as i32 {
                args_print_add(
                    &mut buf as *mut *mut i8,
                    &mut len as *mut size_t,
                    b" -%c\0" as *const u8 as *const i8,
                    (*entry).flag as i32,
                );
            } else {
                args_print_add(
                    &mut buf as *mut *mut i8,
                    &mut len as *mut size_t,
                    b"-%c\0" as *const u8 as *const i8,
                    (*entry).flag as i32,
                );
            }
            last = entry;
        } else if !((*entry).values.tqh_first).is_null() {
            value = (*entry).values.tqh_first;
            while !value.is_null() {
                if *buf as i32 != '\0' as i32 {
                    args_print_add(
                        &mut buf as *mut *mut i8,
                        &mut len as *mut size_t,
                        b" -%c\0" as *const u8 as *const i8,
                        (*entry).flag as i32,
                    );
                } else {
                    args_print_add(
                        &mut buf as *mut *mut i8,
                        &mut len as *mut size_t,
                        b"-%c\0" as *const u8 as *const i8,
                        (*entry).flag as i32,
                    );
                }
                args_print_add_value(&mut buf, &mut len, value);
                value = (*value).entry.tqe_next;
            }
            last = entry;
        }
        entry = args_tree_RB_NEXT(entry);
    }
    if !last.is_null() && (*last).flags & 0x1 as i32 != 0 {
        args_print_add(
            &mut buf as *mut *mut i8,
            &mut len as *mut size_t,
            b" --\0" as *const u8 as *const i8,
        );
    }
    i = 0 as i32 as u_int;
    while i < (*args).count {
        args_print_add_value(
            &mut buf,
            &mut len,
            &mut *((*args).values).offset(i as isize),
        );
        i = i.wrapping_add(1);
    }
    return buf;
}
#[no_mangle]
pub unsafe extern "C" fn args_escape(mut s: *const i8) -> *mut i8 {
    static mut dquoted: [i8; 9] =
        unsafe { *::core::mem::transmute::<&[u8; 9], &[i8; 9]>(b" #';${}%\0") };
    static mut squoted: [i8; 3] =
        unsafe { *::core::mem::transmute::<&[u8; 3], &[i8; 3]>(b" \"\0") };
    let mut escaped: *mut i8 = std::ptr::null_mut::<i8>();
    let mut result: *mut i8 = std::ptr::null_mut::<i8>();
    let mut flags: i32 = 0;
    let mut quotes: i32 = 0 as i32;
    if *s as i32 == '\0' as i32 {
        xasprintf(
            &mut result as *mut *mut i8,
            b"''\0" as *const u8 as *const i8,
        );
        return result;
    }
    if *s.offset(strcspn(s, dquoted.as_ptr()) as isize) as i32 != '\0' as i32 {
        quotes = '"' as i32;
    } else if *s.offset(strcspn(s, squoted.as_ptr()) as isize) as i32 != '\0' as i32 {
        quotes = '\'' as i32;
    }
    if *s.offset(0 as i32 as isize) as i32 != ' ' as i32
        && *s.offset(1 as i32 as isize) as i32 == '\0' as i32
        && (quotes != 0 as i32
            || *s.offset(0 as i32 as isize) as i32 == '~' as i32)
    {
        xasprintf(
            &mut escaped as *mut *mut i8,
            b"\\%c\0" as *const u8 as *const i8,
            *s.offset(0 as i32 as isize) as i32,
        );
        return escaped;
    }
    flags = 0x1 as i32 | 0x2 as i32 | 0x8 as i32 | 0x10 as i32;
    if quotes == '"' as i32 {
        flags |= 0x200 as i32;
    }
    utf8_stravis(&mut escaped, s, flags);
    if quotes == '\'' as i32 {
        xasprintf(
            &mut result as *mut *mut i8,
            b"'%s'\0" as *const u8 as *const i8,
            escaped,
        );
    } else if quotes == '"' as i32 {
        if *escaped as i32 == '~' as i32 {
            xasprintf(
                &mut result as *mut *mut i8,
                b"\"\\%s\"\0" as *const u8 as *const i8,
                escaped,
            );
        } else {
            xasprintf(
                &mut result as *mut *mut i8,
                b"\"%s\"\0" as *const u8 as *const i8,
                escaped,
            );
        }
    } else if *escaped as i32 == '~' as i32 {
        xasprintf(
            &mut result as *mut *mut i8,
            b"\\%s\0" as *const u8 as *const i8,
            escaped,
        );
    } else {
        result = xstrdup(escaped);
    }
    free(escaped as *mut libc::c_void);
    return result;
}
#[no_mangle]
pub unsafe extern "C" fn args_has(mut args: *mut args, mut flag: u_char) -> i32 {
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        return 0 as i32;
    }
    return (*entry).count as i32;
}
#[no_mangle]
pub unsafe extern "C" fn args_set(
    mut args: *mut args,
    mut flag: u_char,
    mut value: *mut args_value,
    mut flags: i32,
) {
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        entry = xcalloc(
            1 as i32 as size_t,
            ::core::mem::size_of::<args_entry>() as u64,
        ) as *mut args_entry;
        (*entry).flag = flag;
        (*entry).count = 1 as i32 as u_int;
        (*entry).flags = flags;
        (*entry).values.tqh_first = std::ptr::null_mut::<args_value>();
        (*entry).values.tqh_last = &mut (*entry).values.tqh_first;
        args_tree_RB_INSERT(&mut (*args).tree, entry);
    } else {
        (*entry).count = ((*entry).count).wrapping_add(1);
    }
    if !value.is_null()
        && (*value).type_0 as u32 != ARGS_NONE as i32 as u32
    {
        (*value).entry.tqe_next = std::ptr::null_mut::<args_value>();
        (*value).entry.tqe_prev = (*entry).values.tqh_last;
        *(*entry).values.tqh_last = value;
        (*entry).values.tqh_last = &mut (*value).entry.tqe_next;
    } else {
        free(value as *mut libc::c_void);
    };
}
#[no_mangle]
pub unsafe extern "C" fn args_get(mut args: *mut args, mut flag: u_char) -> *const i8 {
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        return std::ptr::null::<i8>();
    }
    if ((*entry).values.tqh_first).is_null() {
        return std::ptr::null::<i8>();
    }
    return (**(*((*entry).values.tqh_last as *mut args_values)).tqh_last)
        .c2rust_unnamed
        .string;
}
#[no_mangle]
pub unsafe extern "C" fn args_first(
    mut args: *mut args,
    mut entry: *mut *mut args_entry,
) -> u_char {
    *entry = args_tree_RB_MINMAX(&mut (*args).tree, -(1 as i32));
    if (*entry).is_null() {
        return 0 as i32 as u_char;
    }
    return (**entry).flag;
}
#[no_mangle]
pub unsafe extern "C" fn args_next(mut entry: *mut *mut args_entry) -> u_char {
    *entry = args_tree_RB_NEXT(*entry);
    if (*entry).is_null() {
        return 0 as i32 as u_char;
    }
    return (**entry).flag;
}
#[no_mangle]
pub unsafe extern "C" fn args_count(mut args: *mut args) -> u_int {
    return (*args).count;
}
#[no_mangle]
pub unsafe extern "C" fn args_values(mut args: *mut args) -> *mut args_value {
    return (*args).values;
}
#[no_mangle]
pub unsafe extern "C" fn args_value(mut args: *mut args, mut idx: u_int) -> *mut args_value {
    if idx >= (*args).count {
        return std::ptr::null_mut::<args_value>();
    }
    return &mut *((*args).values).offset(idx as isize) as *mut args_value;
}
#[no_mangle]
pub unsafe extern "C" fn args_string(mut args: *mut args, mut idx: u_int) -> *const i8 {
    if idx >= (*args).count {
        return std::ptr::null::<i8>();
    }
    return args_value_as_string(&mut *((*args).values).offset(idx as isize));
}
#[no_mangle]
pub unsafe extern "C" fn args_make_commands_now(
    mut self_0: *mut cmd,
    mut item: *mut cmdq_item,
    mut idx: u_int,
    mut expand: i32,
) -> *mut cmd_list {
    let mut state: *mut args_command_state = std::ptr::null_mut::<args_command_state>();
    let mut error: *mut i8 = std::ptr::null_mut::<i8>();
    let mut cmdlist: *mut cmd_list = std::ptr::null_mut::<cmd_list>();
    state = args_make_commands_prepare(
        self_0,
        item,
        idx,
        std::ptr::null::<i8>(),
        0 as i32,
        expand,
    );
    cmdlist = args_make_commands(
        state,
        0 as i32,
        std::ptr::null_mut::<*mut i8>(),
        &mut error,
    );
    if cmdlist.is_null() {
        cmdq_error(item, b"%s\0" as *const u8 as *const i8, error);
        free(error as *mut libc::c_void);
    } else {
        (*cmdlist).references += 1;
    }
    args_make_commands_free(state);
    return cmdlist;
}
#[no_mangle]
pub unsafe extern "C" fn args_make_commands_prepare(
    mut self_0: *mut cmd,
    mut item: *mut cmdq_item,
    mut idx: u_int,
    mut default_command: *const i8,
    mut wait: i32,
    mut expand: i32,
) -> *mut args_command_state {
    let mut args: *mut args = cmd_get_args(self_0);
    let mut target: *mut cmd_find_state = cmdq_get_target(item);
    let mut tc: *mut client = cmdq_get_target_client(item);
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    let mut state: *mut args_command_state = std::ptr::null_mut::<args_command_state>();
    let mut cmd: *const i8 = std::ptr::null::<i8>();
    let mut file: *const i8 = std::ptr::null::<i8>();
    state = xcalloc(
        1 as i32 as size_t,
        ::core::mem::size_of::<args_command_state>() as u64,
    ) as *mut args_command_state;
    if idx < (*args).count {
        value = &mut *((*args).values).offset(idx as isize) as *mut args_value;
        if (*value).type_0 as u32 == ARGS_COMMANDS as i32 as u32 {
            (*state).cmdlist = (*value).c2rust_unnamed.cmdlist;
            (*(*state).cmdlist).references += 1;
            return state;
        }
        cmd = (*value).c2rust_unnamed.string;
    } else {
        if default_command.is_null() {
            fatalx(b"argument out of range\0" as *const u8 as *const i8);
        }
        cmd = default_command;
    }
    if expand != 0 {
        (*state).cmd = format_single_from_target(item, cmd);
    } else {
        (*state).cmd = xstrdup(cmd);
    }
    log_debug(
        b"%s: %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 27], &[i8; 27]>(
            b"args_make_commands_prepare\0",
        ))
        .as_ptr(),
        (*state).cmd,
    );
    if wait != 0 {
        (*state).pi.item = item;
    }
    cmd_get_source(self_0, &mut file, &mut (*state).pi.line);
    if !file.is_null() {
        (*state).pi.file = xstrdup(file);
    }
    (*state).pi.c = tc;
    if !((*state).pi.c).is_null() {
        (*(*state).pi.c).references += 1;
    }
    cmd_find_copy_state(&mut (*state).pi.fs, target);
    return state;
}
#[no_mangle]
pub unsafe extern "C" fn args_make_commands(
    mut state: *mut args_command_state,
    mut argc: i32,
    mut argv: *mut *mut i8,
    mut error: *mut *mut i8,
) -> *mut cmd_list {
    let mut pr: *mut cmd_parse_result = std::ptr::null_mut::<cmd_parse_result>();
    let mut cmd: *mut i8 = std::ptr::null_mut::<i8>();
    let mut new_cmd: *mut i8 = std::ptr::null_mut::<i8>();
    let mut i: i32 = 0;
    if !((*state).cmdlist).is_null() {
        if argc == 0 as i32 {
            return (*state).cmdlist;
        }
        return cmd_list_copy((*state).cmdlist, argc, argv);
    }
    cmd = xstrdup((*state).cmd);
    log_debug(
        b"%s: %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b"args_make_commands\0"))
            .as_ptr(),
        cmd,
    );
    cmd_log_argv(
        argc,
        argv,
        (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b"args_make_commands\0"))
            .as_ptr(),
    );
    i = 0 as i32;
    while i < argc {
        new_cmd = cmd_template_replace(cmd, *argv.offset(i as isize), i + 1 as i32);
        log_debug(
            b"%s: %%%u %s: %s\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b"args_make_commands\0"))
                .as_ptr(),
            i + 1 as i32,
            *argv.offset(i as isize),
            new_cmd,
        );
        free(cmd as *mut libc::c_void);
        cmd = new_cmd;
        i += 1;
    }
    log_debug(
        b"%s: %s\0" as *const u8 as *const i8,
        (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b"args_make_commands\0"))
            .as_ptr(),
        cmd,
    );
    pr = cmd_parse_from_string(cmd, &mut (*state).pi);
    free(cmd as *mut libc::c_void);
    match (*pr).status as u32 {
        0 => {
            *error = (*pr).error;
            return std::ptr::null_mut::<cmd_list>();
        }
        1 => return (*pr).cmdlist,
        _ => {}
    }
    fatalx(b"invalid parse return state\0" as *const u8 as *const i8);
}
#[no_mangle]
pub unsafe extern "C" fn args_make_commands_free(mut state: *mut args_command_state) {
    if !((*state).cmdlist).is_null() {
        cmd_list_free((*state).cmdlist);
    }
    if !((*state).pi.c).is_null() {
        server_client_unref((*state).pi.c);
    }
    free((*state).pi.file as *mut libc::c_void);
    free((*state).cmd as *mut libc::c_void);
    free(state as *mut libc::c_void);
}
#[no_mangle]
pub unsafe extern "C" fn args_make_commands_get_command(
    mut state: *mut args_command_state,
) -> *mut i8 {
    let mut first: *mut cmd = std::ptr::null_mut::<cmd>();
    let mut n: i32 = 0;
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    if !((*state).cmdlist).is_null() {
        first = cmd_list_first((*state).cmdlist);
        if first.is_null() {
            return xstrdup(b"\0" as *const u8 as *const i8);
        }
        return xstrdup((*cmd_get_entry(first)).name);
    }
    n = strcspn((*state).cmd, b" ,\0" as *const u8 as *const i8) as i32;
    xasprintf(
        &mut s as *mut *mut i8,
        b"%.*s\0" as *const u8 as *const i8,
        n,
        (*state).cmd,
    );
    return s;
}
#[no_mangle]
pub unsafe extern "C" fn args_first_value(
    mut args: *mut args,
    mut flag: u_char,
) -> *mut args_value {
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        return std::ptr::null_mut::<args_value>();
    }
    return (*entry).values.tqh_first;
}
#[no_mangle]
pub unsafe extern "C" fn args_next_value(mut value: *mut args_value) -> *mut args_value {
    return (*value).entry.tqe_next;
}
#[no_mangle]
pub unsafe extern "C" fn args_strtonum(
    mut args: *mut args,
    mut flag: u_char,
    mut minval: i64,
    mut maxval: i64,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut errstr: *const i8 = std::ptr::null::<i8>();
    let mut ll: i64 = 0;
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    entry = args_find(args, flag);
    if entry.is_null() {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    value = *(*((*entry).values.tqh_last as *mut args_values)).tqh_last;
    if value.is_null()
        || (*value).type_0 as u32 != ARGS_STRING as i32 as u32
        || ((*value).c2rust_unnamed.string).is_null()
    {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    ll = strtonum((*value).c2rust_unnamed.string, minval, maxval, &mut errstr);
    if !errstr.is_null() {
        *cause = xstrdup(errstr);
        return 0 as i32 as i64;
    }
    *cause = std::ptr::null_mut::<i8>();
    return ll;
}
#[no_mangle]
pub unsafe extern "C" fn args_strtonum_and_expand(
    mut args: *mut args,
    mut flag: u_char,
    mut minval: i64,
    mut maxval: i64,
    mut item: *mut cmdq_item,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut errstr: *const i8 = std::ptr::null::<i8>();
    let mut formatted: *mut i8 = std::ptr::null_mut::<i8>();
    let mut ll: i64 = 0;
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    let mut value: *mut args_value = std::ptr::null_mut::<args_value>();
    entry = args_find(args, flag);
    if entry.is_null() {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    value = *(*((*entry).values.tqh_last as *mut args_values)).tqh_last;
    if value.is_null()
        || (*value).type_0 as u32 != ARGS_STRING as i32 as u32
        || ((*value).c2rust_unnamed.string).is_null()
    {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    formatted = format_single_from_target(item, (*value).c2rust_unnamed.string);
    ll = strtonum(formatted, minval, maxval, &mut errstr);
    free(formatted as *mut libc::c_void);
    if !errstr.is_null() {
        *cause = xstrdup(errstr);
        return 0 as i32 as i64;
    }
    *cause = std::ptr::null_mut::<i8>();
    return ll;
}
#[no_mangle]
pub unsafe extern "C" fn args_percentage(
    mut args: *mut args,
    mut flag: u_char,
    mut minval: i64,
    mut maxval: i64,
    mut curval: i64,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut value: *const i8 = std::ptr::null::<i8>();
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    if ((*entry).values.tqh_first).is_null() {
        *cause = xstrdup(b"empty\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    value = (**(*((*entry).values.tqh_last as *mut args_values)).tqh_last)
        .c2rust_unnamed
        .string;
    return args_string_percentage(value, minval, maxval, curval, cause);
}
#[no_mangle]
pub unsafe extern "C" fn args_string_percentage(
    mut value: *const i8,
    mut minval: i64,
    mut maxval: i64,
    mut curval: i64,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut errstr: *const i8 = std::ptr::null::<i8>();
    let mut ll: i64 = 0;
    let mut valuelen: size_t = strlen(value);
    let mut copy: *mut i8 = std::ptr::null_mut::<i8>();
    if valuelen == 0 as i32 as u64 {
        *cause = xstrdup(b"empty\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    if *value.offset(valuelen.wrapping_sub(1 as i32 as u64) as isize)
        as i32
        == '%' as i32
    {
        copy = xstrdup(value);
        *copy.offset(valuelen.wrapping_sub(1 as i32 as u64) as isize) =
            '\0' as i32 as i8;
        ll = strtonum(
            copy,
            0 as i32 as i64,
            100 as i32 as i64,
            &mut errstr,
        );
        free(copy as *mut libc::c_void);
        if !errstr.is_null() {
            *cause = xstrdup(errstr);
            return 0 as i32 as i64;
        }
        ll = curval * ll / 100 as i32 as i64;
        if ll < minval {
            *cause = xstrdup(b"too small\0" as *const u8 as *const i8);
            return 0 as i32 as i64;
        }
        if ll > maxval {
            *cause = xstrdup(b"too large\0" as *const u8 as *const i8);
            return 0 as i32 as i64;
        }
    } else {
        ll = strtonum(value, minval, maxval, &mut errstr);
        if !errstr.is_null() {
            *cause = xstrdup(errstr);
            return 0 as i32 as i64;
        }
    }
    *cause = std::ptr::null_mut::<i8>();
    return ll;
}
#[no_mangle]
pub unsafe extern "C" fn args_percentage_and_expand(
    mut args: *mut args,
    mut flag: u_char,
    mut minval: i64,
    mut maxval: i64,
    mut curval: i64,
    mut item: *mut cmdq_item,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut value: *const i8 = std::ptr::null::<i8>();
    let mut entry: *mut args_entry = std::ptr::null_mut::<args_entry>();
    entry = args_find(args, flag);
    if entry.is_null() {
        *cause = xstrdup(b"missing\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    if ((*entry).values.tqh_first).is_null() {
        *cause = xstrdup(b"empty\0" as *const u8 as *const i8);
        return 0 as i32 as i64;
    }
    value = (**(*((*entry).values.tqh_last as *mut args_values)).tqh_last)
        .c2rust_unnamed
        .string;
    return args_string_percentage_and_expand(value, minval, maxval, curval, item, cause);
}
#[no_mangle]
pub unsafe extern "C" fn args_string_percentage_and_expand(
    mut value: *const i8,
    mut minval: i64,
    mut maxval: i64,
    mut curval: i64,
    mut item: *mut cmdq_item,
    mut cause: *mut *mut i8,
) -> i64 {
    let mut errstr: *const i8 = std::ptr::null::<i8>();
    let mut ll: i64 = 0;
    let mut valuelen: size_t = strlen(value);
    let mut copy: *mut i8 = std::ptr::null_mut::<i8>();
    let mut f: *mut i8 = std::ptr::null_mut::<i8>();
    if *value.offset(valuelen.wrapping_sub(1 as i32 as u64) as isize)
        as i32
        == '%' as i32
    {
        copy = xstrdup(value);
        *copy.offset(valuelen.wrapping_sub(1 as i32 as u64) as isize) =
            '\0' as i32 as i8;
        f = format_single_from_target(item, copy);
        ll = strtonum(
            f,
            0 as i32 as i64,
            100 as i32 as i64,
            &mut errstr,
        );
        free(f as *mut libc::c_void);
        free(copy as *mut libc::c_void);
        if !errstr.is_null() {
            *cause = xstrdup(errstr);
            return 0 as i32 as i64;
        }
        ll = curval * ll / 100 as i32 as i64;
        if ll < minval {
            *cause = xstrdup(b"too small\0" as *const u8 as *const i8);
            return 0 as i32 as i64;
        }
        if ll > maxval {
            *cause = xstrdup(b"too large\0" as *const u8 as *const i8);
            return 0 as i32 as i64;
        }
    } else {
        f = format_single_from_target(item, value);
        ll = strtonum(f, minval, maxval, &mut errstr);
        free(f as *mut libc::c_void);
        if !errstr.is_null() {
            *cause = xstrdup(errstr);
            return 0 as i32 as i64;
        }
    }
    *cause = std::ptr::null_mut::<i8>();
    return ll;
}
